package cn.tx.dao.impl;

import org.apache.commons.lang.StringUtils;

import cn.tx.dao.StoreDetailDao;
import cn.tx.model.StoreDetail;
import cn.tx.query.StoreDetailQuery;

public class StoreDetailDaoImpl extends BaseDaoImpl<StoreDetail, StoreDetailQuery> implements StoreDetailDao {

	@Override
	public String createHql(StoreDetailQuery q) {
		String hql = "from StoreDetail e where 1=1 ";
		String condition = this.createConditionHql(q);
		hql = hql + condition + "order by e.detailId desc";
		return hql;
	}

	@Override
	public String createHqlCount(StoreDetailQuery q) {
		String hql = "select count(e) from StoreDetail e where 1=1 ";
		//StringUtils.isNotBlank判断当前的字符串是不是空串和null
		String condition = this.createConditionHql(q);
		hql = hql + condition;
		return hql;
	}

	@Override
	public String createConditionHql(StoreDetailQuery q) {
		String hql = "";
		if(q.getStoreId() != null){
			hql = hql + "and e.store.storeId = :storeId ";
		}
		if(StringUtils.isNotBlank(q.getpName())){
			hql = hql + "and e.product.name like :pName ";
		}
		if(q.getStartStock() != null){
			hql = hql + "and e.num >= :startStock ";
		}
		
		if(q.getEndStock() != null){
			hql = hql + "and e.num <= :endStock ";
		}
		return hql;
	}



}
